<template>
	<view class="fallback-list">
		<uni-card v-for="(item,index) in fallbackList" :key="item.feedbackRecordId" @click="itemClick(index)">
			<view>反馈问题:{{item.detailCause}}</view>
			<view>状态:{{item.status === 0 ? '处理中':'已处理'}}</view>
			<view>反馈时间:{{item.feedbackTime}}</view>
		</uni-card>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onPullDownRefresh,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		onMounted,
		ref
	} from 'vue'
	import {
		getFallbackSimpleInfo,
	} from '@/service/modules/personal';

	const pageNum = ref(1)
	const fallbackList = ref([])

	// 下拉刷新
	onPullDownRefresh(async () => {
		pageNum.value = 1
		await getList()
		// 请求成功关闭下拉状态
		uni.stopPullDownRefresh()
		console.log('关闭下拉状态');
	})
	// 上拉触底
	onReachBottom(() => {
		if (fallbackList.value.length % 10 === 0) {
			pageNum.value++
			getList(true)
		} else {
			uni.showToast({
				icon: "error",
				title: "已经到底了哦~"
			})
		}
	})

	onMounted(() => {
		getList()
	})

	const itemClick = (index) => {
		const id = fallbackList.value[index].feedbackRecordId
		uni.navigateTo({
			url: `/pages/fallback-detail/fallback-detail?id=${id}`
		})
	}

	const getList = async (isPush) => {
		const res = await getFallbackSimpleInfo(pageNum.value)
		// 触底要追加数据
		if (isPush) {
			fallbackList.value = fallbackList.value.push(...res.data)
		} else {
			// 这是初次加载或者下拉刷新的赋值情况
			fallbackList.value = res.data
		}
		console.log(fallbackList.value);
	}
</script>

<style lang="scss">

</style>